﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {


        }




        private void button2_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(textBox2.Text))
            {
                TemplateHost th = new TemplateHost() { TemplateFile = textBox2.Text };
                string output = new Microsoft.VisualStudio.TextTemplating.Engine().ProcessTemplate(System.IO.File.ReadAllText(th.TemplateFile), th);
                if (th.Errors.Count > 0)
                {
                    foreach (System.CodeDom.Compiler.CompilerError item in th.Errors)
                    {
                        textBox1.AppendText(item.ErrorText + Environment.NewLine);
                    }
                }
                else
                {
                    textBox1.Text = output;
                }
            }
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog obj = new OpenFileDialog())
            {
                obj.Filter = "T4模板(*.tt)|*.tt";
                if (obj.ShowDialog() == DialogResult.OK)
                    this.textBox2.Text = obj.FileName;
            }
        }
    }
}
